﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Pagination.ascx.cs"
    Inherits="Thksoft.UserCotrols.Pagination" %>
<div class="PageIng" style="font-size: 14px; color: #B0B0B0; text-align: center;">
    <button type="button" style="width: 8px; height: 14px; margin: 0; padding: 0; border: 0; outline: none; background-image: url('/Content/Images/左箭头.png'); color: white; background-color: transparent; margin-right: 5px; cursor: pointer;" onclick="window.<%=this.ClientID %>.GoLeft()"></button>
    <div id="<%=(this.ID + "_BT1") %>" style="display: inline-block; font-size: 14px; color: white; margin-left: 5px;">
        <%
            if (PageCount == 1 || PageCount == 0)
            {

        %>
        <button type="button" style="border: 0; background-color: rgb(255,87,34); margin: 3px; padding: 3px 10px; color: white;" onclick="window.<%=this.ClientID %>.Go(1);">1</button>
        <%
            }
        %>
        <%
            if (PageCount > 1)
            {
                var arrry = new List<Tuple<int, bool>>();
                if (CurrentPage == 1)
                {
                    arrry.Add(new Tuple<int, bool>(1, true));
                    if (PageCount >= 3)
                    {
                        arrry.Add(new Tuple<int, bool>(2, false));
                        arrry.Add(new Tuple<int, bool>(3, false));
                    }
                    else
                    {
                        for (int i = PageCount; i > 1; i--)
                        {
                            arrry.Add(new Tuple<int, bool>(i, false));
                        }
                    }
                }
                else
                {
                    arrry.Add(new Tuple<int, bool>(CurrentPage - 1, false));
                    arrry.Add(new Tuple<int, bool>(CurrentPage, true));
                    if (CurrentPage + 1 < PageCount)
                    {
                        arrry.Add(new Tuple<int, bool>(CurrentPage + 1, false));
                    }
                    else if (CurrentPage >= 3)
                    {
                        arrry.Add(new Tuple<int, bool>(CurrentPage - 2, false));
                    }
                }
                foreach (var item in arrry.OrderBy(a => a.Item1))
                {
                    if (item.Item2)
                    {

        %>
        <button type="button" style="border: 0; background-color: rgb(255,87,34); margin: 3px; padding: 3px 10px; color: white;" onclick="window.<%=this.ClientID %>.Go(<%=item.Item1 %>);"><%=item.Item1 %></button>
        <%
            }
            else
            {
        %>
        <button type="button" style="border: 0; margin: 3px; padding: 3px 10px;" onclick="window.<%=this.ClientID %>.Go(<%=item.Item1 %>);"><%=item.Item1 %></button>
        <%
                    }
                }
            }
        %>
    </div>
    <button type="button" style="width: 8px; height: 14px; margin: 0; padding: 0; border: 0; outline: none; background-image: url('/Content/Images/右箭头.png'); color: white; background-color: transparent; margin-left: 5px; cursor: pointer;" onclick="window.<%=this.ClientID %>.GoRight();"></button>
    第
        <asp:TextBox ID="txtCurrentPage" runat="server" Style="width: 30px; background-color: white; border: 0; border: 1px solid #B0B0B0; text-align: center; margin: 3px; padding: 3px 10px;"
            onkeypress="return !String.fromCharCode(event.keyCode).match(/[^0-9]/)" onpaste="return !clipboardData.getData('text').match(/[^0-9]/)"
            AutoPostBack="true" Wrap="False" />
    页
        <asp:Button ID="btnRefresh" runat="server" Text="确定" Style="display: none;" OnClick="btnRefresh_Click"
            ToolTip="输入您想转到的页号，然后敲击“Enter”回车键" Wrap="False" />
    <button onclick="window.<%=this.ClientID %>.Go($('#<%=txtCurrentPage.ClientID %>').val());" type="button" style="color: #000; background-color: white; border: 1px solid #B0B0B0; text-align: center; margin: 3px; padding: 3px 10px;">确定</button>
    共
        <span><%=RowsCount %></span>
    条
        ,
        <asp:Label ID="lblRowCount" runat="server" Style="display: none; font-size: 14px; color: #000;" />
    <span id='<%=lblRowCount.ClientID %>_C'><%=PageCount%></span>
    页
        <select style="border: 1px solid #B0B0B0;" onchange="window.<%=this.ClientID %>.RowsPerPageChange(this);">
            <option value="5" <%=this.RowsPerPage==5?"selected=selected":"" %>>5条/页
            </option>
            <option value="50" <%=this.RowsPerPage==50?"selected=selected":"" %>>50条/页
            </option>
            <option value="100" <%=this.RowsPerPage==100?"selected=selected":"" %>>100条/页
            </option>
            <option value="200" <%=this.RowsPerPage==200?"selected=selected":"" %>>200条/页
            </option>
            <option value="400" <%=this.RowsPerPage==400?"selected=selected":"" %>>400条/页
            </option>
            <option value="800" <%=this.RowsPerPage==800?"selected=selected":"" %>>800条/页
            </option>
            <option value="1600" <%=this.RowsPerPage==1600?"selected=selected":"" %>>1600条/页
            </option>
        </select>
    <button type="button" class="bt_css_s" onclick="window.<%=this.ClientID %>.Go(1);">首页</button>
    <button type="button" class="bt_css_s" onclick="window.<%=this.ClientID %>.GoLeft();">上一页</button>
    <button type="button" class="bt_css_s" onclick="window.<%=this.ClientID %>.GoRight();">下一页</button>
    <button type="button" class="bt_css_s" onclick="window.<%=this.ClientID %>.Go(<%=PageCount%>);">尾页</button>
    <dx:ASPxHiddenField runat="server" ClientInstanceName="HiddenField" ID="HiddenField">
    </dx:ASPxHiddenField>
</div>
<script type="text/javascript">
    //加载方法
    !function () {
        var key = "<%=this.ClientID%>";
        var txtCurrentPage = "<%=txtCurrentPage.ClientID%>";
        var btnRefresh = "<%=btnRefresh.ClientID%>";
        var lblRowCount = "<%=lblRowCount.ClientID%>_C";

        window[key] = {};
        window[key].Go = function (page) {
            if (parseInt(page) > 0 && parseInt(page) <= parseInt($("#" + lblRowCount).text())) {

            }
            else {
                alert("请输入正确的页码！");
                return;
            }

            $("#" + txtCurrentPage).val(page);
            btnRefreshClick();
        };
        window[key].GoLeft = function () {
            if ((parseInt($("#" + txtCurrentPage).val()) - 1) <= 0) {
                alert("已经是第一页了");
                return;
            }

            $("#" + txtCurrentPage).val(parseInt($("#" + txtCurrentPage).val()) - 1);
            btnRefreshClick();
        };
        window[key].GoRight = function () {
            if ((parseInt($("#" + txtCurrentPage).val()) + 1) > parseInt($("#" + lblRowCount).text())) {
                alert("已经是最后一页了");
                return;
            }
            $("#" + txtCurrentPage).val(parseInt($("#" + txtCurrentPage).val()) + 1);
            btnRefreshClick();
        };
        window[key].RowsPerPageChange = function (dom) {
            var value = $(dom).val();

            HiddenField.Set("RowPerValue", value);
            btnRefreshClick();
        };

        function btnRefreshClick() {
            if ((typeof Message) == 'undefined') {
                $("#" + btnRefresh).click();
            } else {
                var f = eval(Message.Get("PagMethod") + "_Click");
                new f("Update");
            }
        }
    }();
</script>